import React from 'react';
import {Redirect, Route, Switch} from 'dva/router';
import DocumentTitle from 'react-document-title';

import {getPageQuery, getQueryPath, getRoutes} from '../utils/utils';
import ComponentBase from '../components/Base/ComponentBase';
import {Layout} from 'antd';

const {Content,  Footer} = Layout;

function getLoginPathWithRedirectPath() {
  const params = getPageQuery();
  const {redirect} = params;
  return getQueryPath('/user/login', {
    redirect,
  });
}

class UserLayout extends ComponentBase {
  render() {
    const {routerData, match} = this.props;
    return (
      <Layout>
        <Content >
          <DocumentTitle title={this.getPageTitle()}>
              <div>
                <Switch>
                  {getRoutes(match.path, routerData).map(item => (
                    <Route
                      key={item.key}
                      path={item.path}
                      component={item.component}
                      exact={item.exact}
                    />
                  ))}
                  <Redirect from="/user" to={getLoginPathWithRedirectPath()}/>
                </Switch>
              </div>

          </DocumentTitle>
        </Content>
        <Footer style={{textAlign: 'center'}}>苏ICP备2021046242号</Footer>
      </Layout>

    );
  }
}

export default UserLayout;
